import React, { Component, Suspense } from 'react'
import {
    Switch,
    Redirect,
    Route
} from 'react-router-dom'
import { ROUTERTYPE } from '../types/router.d'
export class routeview extends Component<ROUTERTYPE> {
    render() {
        let { routes = [] } = this.props
        return (
            <Suspense fallback={<div>加载中...</div>}>
                <Switch>
                    {
                        routes.map((item, index) => {
                            return <Route
                                key={index}
                                path={item.path}
                                render={(props) => {
                                    return item.to ?
                                        <Redirect to={item.to}></Redirect> :
                                        <item.component {...props} children={item.children}></item.component>
                                }}></Route>
                        })
                    }
                </Switch>
            </Suspense>
        )
    }
}

export default routeview
